<!--新增数据字典   数据库管理员-->
<template>
  <div id="CreateDataDictionary">
    <!--         Breadcrumbs -->
    <div class="breadcrumbs" style="margin: 0px;padding-top: 20px;">
      <ul>
        <li class="home"><a href="index.html" title="Go to Home Page"><strong style="font-size: 18px;">基础数据</strong></a>
          <span>/</span>
        </li>
        <li><strong>数据字典管理</strong><span>/</span></li>
        <li><strong>新增数据字典</strong></li>
      </ul>
    </div>
    <article class="col-main">
      <div class="my-account block block-account" style="padding-left: 20px;">

        <div class="page-title" style="border-bottom: #F1F3F6 1px solid;">
          <h2>新增数据字典</h2>
          <hr>
        </div>

        <form action=">">
          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">类别</strong>
            &nbsp;<span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <select v-model="dictionary.parentId" class="form-control" style="width: 400px">
                <option value="0" >-请选择-</option>
                <option value="1" >全部类别</option>
                <option v-for="item in dictionaryTypes" :value=" item.dictionaryId ">{{ item.dictionaryValue }}</option>
              </select>
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">条目</strong>
            <span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <input v-on:blur="checkDictionaryEntry" v-model="dictionary.dictionaryEntry" name="dataDictionaryEntry" class="form-control" placeholder="请输入数据字典的条目" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">值</strong>
            &nbsp;<span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <input v-on:blur="checkDictionaryValue" v-model="dictionary.dictionaryValue" name="dataDictionaryValue" class="form-control" placeholder="请输入数据字典的值" style="width: 400px;">
            </div>
          </div>

          <div class="form-group row">
            <div style="padding-left: 20px;">
              <strong style="font-weight: 1000;font-size: 20px">是否可编辑</strong>
              &nbsp;<span style="color: red;font-size: 15px">*</span>
            </div>
              <div style="padding-left: 40px;">
                <input v-model="dictionary.isEdit" type="radio" value="1" name="isEdit" > 可编辑 &nbsp;&nbsp;
                <input v-model="dictionary.isEdit" type="radio" value="0" name="isEdit" > 不可编辑
              </div>
          </div>

          <div class="text-center" style="margin-top: 40px;padding-bottom: 30px">
            <input v-on:click="saveDictionary" type="button" class="btn btn-primary" value="保存">
            <router-link to="DataDictionaryList" class="btn btn-default">返回</router-link>
          </div>
        </form>

      </div>
    </article>
  </div>
</template>

<script>
export default {
  name: "CreateDataDictionary",
  data(){
    return{
      dictionaryTypes:[],
      dictionary:{
        parentId:0,
        dictionaryValue:'',
        dictionaryEntry:'',
        isEdit:'',
      }
    }
  },
  methods:{
    loadDictionaryTypes(){
      this.$axios.get("/dictionary/loadDictionaryTypes").then(
        res=>{
          this.dictionaryTypes = res.data.data.dictionaryTypes;
        }
      )
    },
    saveDictionary(){
      if (this.checkDictionaryEntry()){
        if (this.checkDictionaryValue()){
          if (this.dictionary.paremtId ==0){
            this.$message({
              showClose: true,
              message: '数据字典类别不可为空',
              type: 'success'
            });
            return;
          }else if (this.dictionary.isEdit == ''){
            this.$message({
              showClose: true,
              message: '请选择改数据是否可编辑',
              type: 'success'
            });
            return;
          }else {
            this.$axios.post("/dictionary/saveDictionary",this.dictionary).then(
              res=>{
                this.$message({
                  showClose: true,
                  message: res.data.message,
                  type: 'success'
                });
                this.$router.push("/MemuBar/DataDictionaryList")
              }
            )
          }
        }
      }
    },
    checkDictionaryEntry(){
      if (this.dictionary.dictionaryEntry == ''){
        this.$message({
          showClose: true,
          message: '数据字典条目不能为空',
          type: 'success'
        });
        return false;
      }else if (this.dictionary.dictionaryEntry.length>=20){
        this.$message({
          showClose: true,
          message: '字数太长，请重输',
          type: 'success'
        });
        return false;
      }else {
        return true;
      }
    },
    checkDictionaryValue(){
      if (this.dictionary.dictionaryValue == ''){
        this.$message({
          showClose: true,
          message: '数据字典的值不能为空',
          type: 'success'
        });
        return false;
      }else if (this.dictionary.dictionaryValue.length>=20){
        this.$message({
          showClose: true,
          message: '字数太长，请重输',
          type: 'success'
        });
        return false;
      }else {
        return true;
      }
    }
  },
  created() {
    this.loadDictionaryTypes()
  }
}
</script>

<style scoped>

</style>
